package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.common.PageResult;
import com.heima.mapper.VmTypeMapper;
import com.heima.pojo.VmType;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.VmTypeDTO;
import com.heima.service.VmTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VmTypeServiceImpl implements VmTypeService {

    @Autowired
    private VmTypeMapper vmTypeMapper;
    @Override
    public PageResult vmTypeQuery(PageQueryDTO dto) {
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        Page<VmType> page = vmTypeMapper.vmTypeQuery(dto);
        return new PageResult(dto.getPageIndex(),dto.getPageSize(),page.getPages(), page.getTotal(),page.getResult());
    }

    @Override
    public Boolean add(VmType vmType) {
        int result = vmTypeMapper.insert(vmType);
        return result != 0;
    }

    @Override
    public Boolean update(Integer typeId, VmType vmType) {
        vmType.setTypeId(typeId);
        int result = vmTypeMapper.updateById(vmType);
        return result != 0;
    }

    @Override
    public Boolean delete(Integer typeId) {
        int result = vmTypeMapper.deleteById(typeId);
        return result != 0;
    }

    @Override
    public VmType queryTypeId(Integer typeId) {
        return vmTypeMapper.selectById(typeId);
    }



}
